﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace jobsheetFinal
{
    public partial class formRegisterNewUser : Form
    {
        public formRegisterNewUser()
        {
            InitializeComponent();
        }

        private void btnCreateAccount_Click(object sender, EventArgs e)
        {
            string firstName = tbxFirstName.Text;
            string lastName = tbxLastName.Text;
            string jobTitle = comboPosition.Text;

            string emailAddress = tbxEmailAddress.Text;
            string userName = tbxUserName.Text;
            string password = tbxPassword1.Text;
            string confirmPassword = tbxPassword2.Text;
            //confirmPassword is to check the valid password for user //

            //Create new object to insert in dataqbase//
            User newUser = new User(firstName, lastName, jobTitle, emailAddress, userName, password);
            
            //inseart created new user//
            //Check Admin or Sales//

            if (jobTitle == "Admin")
            {
                DBManager.RegisterNewUser_Admin(newUser);
            }
            else
            {
                DBManager.RegisterNewUser_Sales(newUser);
            }

            tbxFirstName.Clear();
            tbxLastName.Clear();
            tbxEmailAddress.Clear();
            tbxPassword1.Clear();
            tbxPassword2.Clear();
            tbxUserName.Clear();


            this.Hide();
            AllFormClass.LoginForm.Show();

            this.Hide();
            AllFormClass.LoginForm.Show();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            // Page Connection
            this.Hide();
            AllFormClass.LoginForm.Show();
        }
    }
}
